#ifndef _msgwin_h_
#define _wsgwin_h_



#include <qdialog.h>
#include <qlayout.h>
#include <qlabel.h>
#include <qdatetime.h>
#include <qsettings.h>
#include <qtimer.h>

class MsgWin : public QDialog {
Q_OBJECT
   private:
      QLabel* lbl;
      int closeTime;
      QTimer* ptimer;
      
   public:

      MsgWin(QWidget *parent = 0, const char *name = 0 , bool modal=FALSE,  WFlags f=(WStyle_Customize | WStyle_NormalBorder | WStyle_DialogBorder | WStyle_StaysOnTop | WStyle_Tool | WStyle_Title | WStyle_SysMenu) )
   : QDialog(parent, name, modal, f)
   {

     lbl = new QLabel(this);

       QHBoxLayout *mainLayout = new QHBoxLayout(this);
       mainLayout->addWidget(lbl);

       closeTime = 0;
       ptimer = new QTimer(this);
       connect(ptimer, SIGNAL(timeout()),this, SLOT(autoClose()));
       ptimer->stop();
       
       readSettings();
  }
  
  ~MsgWin(){
     hide();
     writeSettings();
  }

   public slots:
      
      void autoClose(){
         
         ptimer->stop();
         hide();
      }
      
      
      void setText(const QString& st)
      {

         QString str = QDateTime::currentDateTime().toString(LocalDate);
         setCaption(str);

         setMinimumWidth(300);
         lbl->setTextFormat(RichText);
         lbl->setText(st);
         QSize size = lbl->sizeHint();
         resize(size);
         showNormal();
         ptimer->stop();
         
         if (closeTime)
         ptimer->start(closeTime * 1000,true);
      
      }

      void setAutoCloseTime(int &time){
          closeTime = time;
      }
   
   protected:

      void keyReleaseEvent(QKeyEvent* event){

         if ((event->key() == Key_Space) ||
              (event->key() == Key_Return) ||
               (event->key() == Key_Enter)){

               hide() ;
         }

      }

      void  readSettings(){
         QSettings settings;
         settings.setPath("sftinc.com", "monitor_a");
         settings.beginGroup("/monitor_a");
         int x = settings.readNumEntry("/msgwin/x", 400);
         int y = settings.readNumEntry("/msgwin/y", 400);
         closeTime = settings.readNumEntry("/monitor/HideMsgWindow",0);
         
         move(x,y);
      }

      void  writeSettings(){
         QSettings settings;
         settings.setPath( "sftinc.com", "monitor_a" );
         settings.beginGroup("/monitor_a");

         settings.writeEntry("/msgwin/x", x());
         settings.writeEntry("/msgwin/y", y());
         settings.endGroup();

      }
};


#endif  //_Shell_h_
